package im.starchat.chat.dialog;

import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import im.starchat.chat.R;
import im.starchat.chat.view.CircularImageButton;
import im.starchat.chat.rest.model.MemberInfo;

/**
 * Created by skyfishjy on 1/6/15.
 */
public class MemberDialogFragment extends DialogFragment {
    Dialog dialog;

    private ImageView mClose;
    private CircularImageButton mHeaderCover;
    private TextView mName;
    private TextView mSex;
    private TextView mDescribe;

    private static final String MEMBER_INFO = "member_info";
    private MemberInfo mMemberInfo;

//    public static MemberDialogFragment newInstance() {
//        MemberDialogFragment comicDetailFragment = new MemberDialogFragment();
//        return comicDetailFragment;
//    }

    public static MemberDialogFragment newInstance(MemberInfo memberInfo) {
        MemberDialogFragment fragment = new MemberDialogFragment();
        Bundle bundle = new Bundle();
        bundle.putParcelable(MEMBER_INFO, memberInfo);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mMemberInfo = getArguments().getParcelable(MEMBER_INFO);
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        LayoutInflater inflater = getActivity().getLayoutInflater();
        View view = inflater.inflate(R.layout.dialog_member, null);
        builder.setView(view);
        dialog = builder.create();
        mClose = (ImageView)view.findViewById(R.id.close);
        mClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
        mHeaderCover = (CircularImageButton)view.findViewById(R.id.avator);
        mName = (TextView)view.findViewById(R.id.name);
        mSex = (TextView)view.findViewById(R.id.sex);
        mDescribe = (TextView)view.findViewById(R.id.describe);

        if(mMemberInfo != null){
            if (!TextUtils.isEmpty(mMemberInfo.getHeadImagePath())) {
                Picasso.with(getActivity()).load(mMemberInfo.getHeadImagePath())
                        .placeholder(R.drawable.home_head)
                        .into(mHeaderCover);
            }
            mName.setText(mMemberInfo.getUserName());
            if(!TextUtils.isEmpty(mMemberInfo.getUserDescribe())){
                mDescribe.setText(mMemberInfo.getUserDescribe());
            }else{
                mDescribe.setVisibility(View.GONE);
            }

        }



        return dialog;
    }



}
